frappe.query_reports["Financial Statements CN"] = {
    "filters": [
        {
            "fieldname": "company",
            "label": __("Company"),
            "fieldtype": "Link",
            "options": "Company",
            "default": frappe.defaults.get_user_default("Company"),
            "reqd": true
        },
        {
            "fieldname": "filter_based_on",
            "label": __("Filter Based On"),
            "fieldtype": "Select",
            "options": ["Fiscal Year", "Date Range"],
            "default": "Fiscal Year",
            "reqd": true
        },
        {
            "fieldname": "from_fiscal_year",
            "label": __("From Fiscal Year"),
            "fieldtype": "Link",
            "options": "Fiscal Year",
            "default": frappe.defaults.get_user_default("fiscal_year"),
            "reqd": true,
            "depends_on": 'eval:doc.filter_based_on === "Fiscal Year"'
        },
        {
            "fieldname": "to_fiscal_year",
            "label": __("To Fiscal Year"),
            "fieldtype": "Link",
            "options": "Fiscal Year",
            "default": frappe.defaults.get_user_default("fiscal_year"),
            "reqd": true,
            "depends_on": 'eval:doc.filter_based_on === "Fiscal Year"'
        },
        {
            "fieldname": "period_start_date",
            "label": __("Start Date"),
            "fieldtype": "Date",
            "reqd": true,
            "depends_on": 'eval:doc.filter_based_on === "Date Range"'
        },
        {
            "fieldname": "period_end_date",
            "label": __("End Date"),
            "fieldtype": "Date",
            "reqd": true,
            "depends_on": 'eval:doc.filter_based_on === "Date Range"'
        },
        {
            "fieldname": "periodicity",
            "label": __("Periodicity"),
            "fieldtype": "Select",
            "options": ["Monthly", "Quarterly", "Half-Yearly", "Yearly"],
            "default": "Monthly",
            "reqd": true
        },
        {
            "fieldname": "accumulated_values",
            "label": __("Accumulated Values"),
            "fieldtype": "Check",
            "default": 1
        },
        // 新增：同比和预算对比开关
        {
            "fieldname": "show_yoy",
            "label": __("Show Year on Year"),
            "fieldtype": "Check"
        },
        {
            "fieldname": "show_budget",
            "label": __("Show Against Budgeting"),
            "fieldtype": "Check"
        }
    ],

    "onload": function(report) {
        // 加载时初始化列设置
        report.page.add_inner_button(__("Reset Columns"), function() {
            report.refresh();
        });
    },

    "formatter": function(value, row, column, data, default_formatter) {
        // 格式化数值（保留两位小数，负数标红）
        value = default_formatter(value, row, column, data);
        if (column.fieldtype === "Currency" && flt(value) < 0) {
            value = $(value).css("color", "red").prop("outerHTML");
        }
        return value;
    },

    "get_datatable_options": function() {
        return {
            "column_widths": {
                "account_name": 300  // 账户名称列宽度
            }
        };
    }
};
